#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution
// 
// Project :JackieHan.DotNet.NMockExample
// 
// File : TestCurrencyService.cs
// 
// CopyRight : Copyright © 2010-2011 JackieHan, All Rights Reserved 
// 
// Summary : 使用NMock测试
// 
// History : 
//			2010-11-24 11:48:34	    Create 
// 

#endregion

#region Using

using System;
using System.Linq;
using System.Collections.Generic;
using NUnit.Framework;
using NMock2;

#endregion

namespace JackieHan.DotNet.NMockExample
{
    /// <summary> 
    /// 使用NMock测试
    /// </summary>
    [TestFixture]
    public class TestCurrencyService
    {
        private Mockery mocks;
        private ICurrencyService mockCurrencyService;
        private IAccountService accountService;

        [SetUp]
        public void SetUp()
        {
            mocks = new Mockery();
            mockCurrencyService = mocks.NewMock<ICurrencyService>();
            accountService = new AccountService(mockCurrencyService);
        }

        [Test]
        public void ShouldUseCurrencyServiceToDetermineConversionRateBetweenAccounts()
        {
            Account canadianAccount = new Account("12345", "CAD");
            Account britishAccount = new Account("54321", "GBP");
            britishAccount.Deposit(100);

            Expect.Once.On(mockCurrencyService)
                .Method("GetConversionRate")
                .With("GBP", "CAD")
                .Will(Return.Value(2.20));

            accountService.TransferFunds(britishAccount, canadianAccount, 100);

            Assert.AreEqual(0, britishAccount.Balance);
            Assert.AreEqual(220, (int)canadianAccount.Balance);
            mocks.VerifyAllExpectationsHaveBeenMet();
        }

        [TearDown]
        public void TearDown()
        {
        }
    }
}